<style scoped lang='less'>
    .holiday-list-mian {
        .action-cell {
            margin-bottom: 20px;
        }

        .home-list .search-block {
            display: flex;
            margin-bottom: 10px;
        }

        .input-search {
            margin-right: 10px;
            margin-bottom: 10px;
        }

        .home-list .selected-search {
            height: 200px;
            width: 100%;
            position: relative;
            border-radius: 4px;
            margin-bottom: 10px;

        }

        .home-list .selected-search .search-action {
            position: absolute;
            top: 10px;
            left: 10px;
            right: 10px;
        }

        .home-list .selected-search .selected-arr {
            position: absolute;
            top: 50px;
            left: 20px;
            right: 20px;
            bottom: 10px;
            overflow: scroll;
        }

        .home-list .select-click {
            border: 1px solid #dddee1;
            border-radius: 4px;
            padding: 10px;
            font-weight: 500;
            text-align: center;
            width: 260px;
            margin-bottom: 10px;
        }

        .home-list .selected-search .selected-arr .selected-item {
            /*border-bottom: 1px solid #dfdfdf;*/
            margin-bottom: 10px;
            font-size: 15px;
        }
    }

</style>
<template>
    <div class="holiday-list-mian">
        <h4>派车管理</h4>
        <Alert show-icon>
            此处用于显示派车管理。
        </Alert>
        <Row>
            <Col>
                <Table :context="self" :data="tableData" :columns="tableColumns" stripe border></Table>
            </Col>
        </Row>
<!--        <div style="margin: 10px;overflow: hidden">-->
<!--            <div style="float: right;">-->
<!--                <Page :total="total" size="large" show-total :current="current" show-elevator show-sizer-->
<!--                      @on-change="changePage"></Page>-->
<!--            </div>-->
<!--        </div>-->
        <!--<Modal-->
        <!--v-model="modalIsShow"-->
        <!--title="选择下级审核员"-->
        <!--@on-ok="postNext"-->
        <!--@on-cancel="cancel">-->
        <!--<div class="home-list search-block">-->
        <!--<p>审核员：{{personalName}}</p>-->
        <!--<div v-if="selectPeopelIsShow" class="selected-search">-->
        <!--<div class="search-action">-->
        <!--<i-input class="input-search" v-model="nextName" placeholder="查询人姓名"></i-input>-->
        <!--</div>-->
        <!--<div class="selected-arr">-->
        <!--<template v-if="principalArr.length < 0">-->
        <!--<p class="selected-item">暂无数据</p>-->
        <!--</template>-->
        <!--<template v-else>-->
        <!--<template v-for="(item,index) in principalArr">-->
        <!--<p @click="choosePeople(item.id,item.personalname)" class="selected-item">-->
        <!--{{item.personalname}}</p>-->
        <!--</template>-->
        <!--</template>-->
        <!--</div>-->
        <!--</div>-->
        <!--</div>-->
        <!--</Modal>-->
        <!--审核操作-->
        <Modal v-model="setCheckIsShow" title="审核" @on-ok="handleSubmit('formValidate')"
               @on-cancel="setPwdIsShow =false">
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
                <Form-item label="绑定车辆" prop="isNeedOtherChecker">
                    <i-select v-model="formValidate.carId" placeholder="请选择绑定车辆">
                        <template v-for="(item,index) in mgrCar">
                            <i-option :value="item.Id">{{item.Carcode}}</i-option>
                        </template>
                    </i-select>
                </Form-item>
            </Form>
        </Modal>
    </div>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import {Modal} from 'view-design'
    import selectSearch from '../../components/selectSearch';


    export default {
        data() {
            return {
                //审核
                setCheckIsShow: false,
                formValidate: {
                    carId:'',
                },
                ruleValidate: {},
                mgrCar: [],
                checkRow: '',
                //表格数据
                self: this,
                tableData: [],
                total: 0,
                current: 1,
                //派车单id
                timeid:'',
                tableColumns: [
                    {
                        title: '申请人',
                        key: 'Displayname',
                        align: 'center',
                    },
                    {
                        title: '申请人电话',
                        key: 'Phone',
                        align: 'center',
                    },
                    {
                        title: '申请人单位',
                        key: 'Unit',
                        align: 'center',
                    },
                    {
                        title: '申请人部门',
                        key: 'Part',
                        align: 'center',
                    },
                    {
                        title: '用车原因',
                        key: 'Reason',
                        align: 'center',
                    },
                    {
                        title: '用车类型',
                        key: 'UseCarType',
                        align: 'center',
                    },
                    {
                        title: '开始日期',
                        key: 'Startdate',
                        align: 'center',
                    },
                    {
                        title: '返回日期',
                        key: 'Enddate',
                        align: 'center',
                    },
                    // {
                    //     title: '审核状态',
                    //     key: 'State',
                    //     align: 'center',
                    // },
                    // {
                    //     title: '派车状态',
                    //     key: 'State',
                    //     align: 'center',
                    // },
                    {
                        title: '操作',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            // if (params.row.Carstate == '未派车') {
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'error',
                                            size: 'small'
                                        },
                                        style: {
                                            // background: '#e4e4e4',
                                            // border: '1px solid #d5d5d5',
                                            // 'margin-bottom':'10px',
                                        },
                                        on: {
                                            click: () => {
                                                this.showCheckModal(params.row.Timeid);
                                            }
                                        }
                                    }, '派车'),
                                ])
                            // }
                            // if(params.row.Carstate == '已派车'){
                            //     return h('div', [
                            //         h('Button', {
                            //             props: {
                            //                 type: 'error',
                            //                 size: 'small'
                            //             },
                            //             style: {
                            //             },
                            //             on: {
                            //                 click: () => {
                            //                     this.cancelApply(params.row)
                            //                 }
                            //             }
                            //         }, '取消派车'),
                            //     ])
                            // }
                        }
                    }
                ]
            }
        },
        mounted() {
            let that = this;
            this.mockTableData();
            this.getCompentensData();

        },
        components: {
            selectSearch
        },
        watch: {
            nextName: function (newVale, oldVale) {
                if (newVale != oldVale) {
                    this.searchNext(newVale);
                }
            }
        },
        component: {
            Modal
        },
        methods: {
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },

            mockTableData() {
                let that = this;
                let para = {
                    // curr: this.current,
                    // page: 10,
                    id:sessionStorage.getItem('userId'),
                };
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.GetCarMgrUseRequest, para, function (res) {
                    that.$Loading.finish();
                    // that.total = res.Msg.TotalCount;
                    // that.current = res.Msg.CurrentPage;
                    that.tableData = res.Msg;
                });
            },
            //取消用车申请
            cancelApply: function (row) {

                let that = this;


                this.$Modal.confirm({
                    title: '提示',
                    content: `确认取消派车申请吗?`,
                    onOk: function () {
                        let para = {
                            requestId: row.Id,
                        }
                        let params = that.$qs.stringify(para);

                        this.$Loading.start();

                        apiUtil.post(that, apiUtil.urls.CancelBindCarToRequest, params, function (res) {
                            that.$Loading.finish();

                            that.mockTableData();

                        });
                    }
                })
            },
            changePage(row) {
                // 这里直接更改了模拟的数据，真实使用场景应该从服务端获取数据
                console.log("row", row);
                this.current = row;
                this.mockTableData();
            },


            /**
             * 审核
             */


            //获取用车列表
            getCompentensData: function () {
                let that = this;
                let params = {
                    opId:sessionStorage.getItem('userId'),
                };
                apiUtil.get(that, apiUtil.urls.MgrCars, params, function (res) {
                    that.mgrCar = res.Msg;
                });
            },
            showCheckModal: function (id) {
                this.setCheckIsShow = true;
                this.timeid = id;
            },
            handleSubmit(name) {
                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.comfirmModifyPS(model);
                })
            },
            comfirmModifyPS: function (model) {
                let that = this;
                model.opId = sessionStorage.getItem('userId');
                model.timeid = this.timeid;

                let params = that.$qs.stringify(model);
                apiUtil.post(that, apiUtil.urls.BindCarToRequest, params, function (res) {
                    that.$Notice.open({
                        title: '提示',
                        desc: '绑定成功 '
                    });
                    that.mockTableData();
                });
            },
        },
    }
</script>
